#include "system.h"

namespace sys
{

	Point operator- (const Point &p1, const Point &p2)
	{
		return Point(p1.x-p2.x,p1.y-p2.y);
	}

	Point operator+ (const Point &p1, const Point &p2)
	{
		return Point(p1.x+p2.x,p1.y+p2.y);
	}

	void Point::Subtract(const Point &p)
	{
		x -= p.x;
		y -= p.y;
	}

	void Point::Add(const Point &p)
	{
		x += p.x;
		y += p.y;
	}

	void Point::Set(const long px, const long py)
	{
		x = px;
		y = py;
	}


	Rect::Rect()
	{
		left =  top = right = bottom = 0;
	}

	Rect::Rect(const int l, const int t, const int r, const int b, const bool isSize)
	{
		left = l;
		top = t;
		right = isSize?l+r:r;
		bottom = isSize?t+b:b;
	}

	void Rect::SetLeftTop(const Point& p)
	{
		left = p.x;
		top = p.y;
	}

	void Rect::SetRightBottom(const Point& p)
	{
		right = p.x;
		bottom = p.y;
	}

	void Rect::Set(const int left,
	  				 const int top,
	         const int right,
	         const int bottom)
	{
		SetLeftTop(Point(left,top));
		SetRightBottom(Point(right,bottom));
	}

	void Rect::SetSquare(const Point& pos, const int size)
	{
		SetLeftTop(pos);
		SetRightBottom(Point(pos.x+size,pos.y+size));
	}

	void Rect::Subtract(const Rect &r1, const Rect &r2)
	{
		left = r1.left - r2.left;
		top = r1.top - r2.top;
		bottom = r1.bottom - r2.bottom;
		right = r1.right - r2.right;
	}

	void Rect::Subtract(const Rect &r)
	{
		left -= r.left;
		right -= r.right;
		top -= r.top;
		bottom -= r.bottom;
	}

	void Rect::Move(const Point &p)
	{
		OffsetRect(this,p.x,p.y);
	}

	void Rect::Move(const Rect &r)
	{
		OffsetRect(this,r.left,r.top);
	}

	void Rect::MoveTo(const Rect &r)
	{
		Point delta(r.left-left,r.top-top);
		Move(delta);
	}

	void Rect::MoveTo(const Point &p)
	{
		Point delta(p.x-left,p.y-top);
		Move(delta);
	}

	void Rect::MoveTo(const int x, const int y)
	{
		Move(Point(x-left,y-top));
	}

	void Rect::Inflate(const int size)
	{
		::InflateRect(this,size,size);
	}


}


